<?php
class View_FeedBack{

	public static function displayListOfBugs($arrBugs, $userRole, $curedFlag = false, $get = NULL, $count){
		$objSession = User_Session::instance();
		$idCurUser = $objSession->getUserId();
		$size = sizeof($arrBugs);
		echo '
		<div class="blueTitle"><div><div><div><div>
			<h1 class="blockName">Баги, отзывы, пожелания (' . $count . ')</h1>
		</div></div></div></div></div>';
		self::displayFilterFormForAdmin($get, $userRole);
		echo '
		<table>
			<tr>
				<th>№</th>
				<th>Текст сообщения</th>
				<th><img src="' . W_IMAGES . 'icons/img_qwestion_2.gif" /></th>
				<th>Время' . ($curedFlag ? ', исправлен' : '') . '</th>'; if ($userRole == 2) echo '
				<th>Юзер</th>
				<th>Агент</th>'; echo '
				<th>Url</th>
				<th>Width</th>
				<th>От разработчиков</th>
				<th width="100">Статус</th>';
				if ($userRole == 2) echo '
					<th>Ответственный</th>
					<th>Приоритет</th>';
			echo '
				<th>Оценка</th>
			</tr>';
			for ($num = 0; $num < $size; $num++){
				$arrBugs[$num]['url'] = str_replace('amp;', '&', $arrBugs[$num]['url']);
				if ($arrBugs[$num]['prog_message'] == NULL)
					$arrBugs[$num]['prog_message'] = 0;
				echo '
				<tr id="bug' . $arrBugs[$num]['ID_feed_back'] . '" class="bugStatus' . ($arrBugs[$num]['status'] == 0 ? '' : $arrBugs[$num]['status']) . '">
					<td><a href="' . W_ABSPATH . 'bug/' . $arrBugs[$num]['ID_feed_back'] . '" class="bug_link black">' . $arrBugs[$num]['ID_feed_back'] . '</a></td>
					<td><a href="' . W_ABSPATH . 'bug/' . $arrBugs[$num]['ID_feed_back'] . '" class="bug_link black">' . $arrBugs[$num]['text'] . ($idCurUser == $arrBugs[$num]['ID_user'] ? '<p><a href="javascript:deleteBug(' . $arrBugs[$num]['ID_feed_back'] . ')" title="удалить">Удалить баг</a></p>' : '') . '</a></td>
					<td><a href="' . W_ABSPATH . 'bug/' . $arrBugs[$num]['ID_feed_back'] . '#comments" class="bug_link black">' . $arrBugs[$num]['comment_amount'] . '</a></td>
					<td>'.Service_Date::getCaseDateForUser($arrBugs[$num]['creation']) . ($curedFlag ? '<br/>' . Service_Date::getCaseDateForUser($arrBugs[$num]['update_time']) : '') . '</td>'; if ($userRole == 2) echo '
					<td>' . (isset($arrBugs[$num]['e_mail']) ? $arrBugs[$num]['e_mail'] : '<a class="black" href="' . W_ABSPATH . 'user/' . $arrBugs[$num]['login'] . '">' . $arrBugs[$num]['login'] . '<br/><a class="black" href="' . W_ABSPATH . 'userBugs/' . $arrBugs[$num]['login'] . '">Баги</a> ') . '</td>
					<td><span title="' . $arrBugs[$num]['agent'] . '">агент</span></td>'; echo '
					<td><a class="black" style="" href="' . W_ABSPATH . ($arrBugs[$num]['url'] != 'index' ? $arrBugs[$num]['url'] : NULL) . '">' . Service_String::cutString($arrBugs[$num]['url'], 15) . '</a></td>
					<td>' . ($arrBugs[$num]['width'] ? $arrBugs[$num]['width'] : '&ndash;') . '</td>
					<td id="tdMessage_' . $arrBugs[$num]['ID_feed_back'] . '" >
						<p id="progMessage_' . $arrBugs[$num]['ID_feed_back'] . '" ';
							if ($userRole == 2) echo '
							 onDblClick="showEditForm(this.tdMessage, ' . $arrBugs[$num]['ID_feed_back'] . ')"';
							echo '
							 attrText="' . $arrBugs[$num]['prog_message'] . '">
							' . ($arrBugs[$num]['prog_message'] === 0 ? '&ndash;' : $arrBugs[$num]['prog_message']) . '
						</p>
					</td>
					<td>';
						if ($userRole == 2){ echo '
							<form class="changeStatus" action="" attrCurForm="changeStatus_' . $arrBugs[$num]['ID_feed_back'] . '">
								<select class="status" style="width: 100px;" onChange="if(confirm(\'Вы уверены?\')) statusUpdate(' . $arrBugs[$num]['ID_feed_back'] . '); else window.location.reload();">
									<option value="0" '; if ($arrBugs[$num]['status'] == NULL) echo 'selected="selected"'; echo '>не рассмотрено</option>
									<option value="1" '; if ($arrBugs[$num]['status'] == 1) echo 'selected="selected"'; echo '>отложено до лучших времен</option>
									<option value="2" '; if ($arrBugs[$num]['status'] == 2) echo 'selected="selected"'; echo '>в процессе</option>
									<option value="3" '; if ($arrBugs[$num]['status'] == 3) echo 'selected="selected"'; echo '>исправлено</option>
									<option value="4" '; if ($arrBugs[$num]['status'] == 4) echo 'selected="selected"'; echo '>мы не считаем это багом</option>
									<option value="5" '; if ($arrBugs[$num]['status'] == 5) echo 'selected="selected"'; echo '>удален(без отправки уведомления)</option>
								</select>
							</form>';
						}
						else{
							switch ($arrBugs[$num]['status']){
								case NULL: echo 'не рассмотрено'; break;
								case 1: echo 'отложено до лучших времен'; break;
								case 2: echo 'в процессе'; break;
								case 3: echo 'исправлено'; break;
								case 4: echo 'мы не считаем это багом'; break;
							}
						}echo '
					</td>';
					if ($userRole == 2){ echo '
					<td>
						<form class="changeResponsible" action="" attrCurForm="changeResponsible_' . $arrBugs[$num]['ID_feed_back'] . '">
							<select class="responsible" onChange="responsibleUpdate(' . $arrBugs[$num]['ID_feed_back'] . '); return false;">
								<option value="0" '; if ($arrBugs[$num]['responsible'] == NULL) echo 'selected="selected"'; echo '>-</option>
								<option value="1" '; if ($arrBugs[$num]['responsible'] == 1) echo 'selected="selected"'; echo '>Виталик</option>
								<option value="3" '; if ($arrBugs[$num]['responsible'] == 3) echo 'selected="selected"'; echo '>Дима</option>
								<option value="4" '; if ($arrBugs[$num]['responsible'] == 4) echo 'selected="selected"'; echo '>Максим</option>
								<option value="5" '; if ($arrBugs[$num]['responsible'] == 5) echo 'selected="selected"'; echo '>Тема</option>
								<option value="6" '; if ($arrBugs[$num]['responsible'] == 6) echo 'selected="selected"'; echo '>Саша</option>
							</select>
						</form>
					</td>
					<td>
						<form class="changePriority" action="" attrCurForm="changePriority_' . $arrBugs[$num]['ID_feed_back'] . '">
							<select class="priority" onChange="priorityUpdate(' . $arrBugs[$num]['ID_feed_back'] . '); return false;">
								<option value="0" '; if ($arrBugs[$num]['priority'] == NULL) echo 'selected="selected"'; echo '>-</option>
								<option value="1" '; if ($arrBugs[$num]['priority'] == 1) echo 'selected="selected"'; echo '>Высокий</option>
								<option value="2" '; if ($arrBugs[$num]['priority'] == 2) echo 'selected="selected"'; echo '>Средний</option>
								<option value="3" '; if ($arrBugs[$num]['priority'] == 3) echo 'selected="selected"'; echo '>Низкий</option>
							</select>
						</form>
					</td>';
					}
					echo '<td style="background:#FFFFFF;">
						<div class="rigt_rating_box">' .
						View_Poll::showMark($arrBugs[$num]['ID_feed_back'], 17, $arrBugs[$num]['session_user_poll'], Poll::calculateMark($arrBugs[$num]['marks_minus'], $arrBugs[$num]['marks_plus']), $arrBugs[$num]['marks_minus'], $arrBugs[$num]['marks_plus'], true) .
						'</div>
					</td>';
					echo '
				</tr>';
			}
			echo '
		</table>
		';
	}

	/**
	 * вывод формы фильтрации багов по ответсвенному и статусу
	 */
	public static function displayFilterFormForAdmin($get, $userRole){
		if ($userRole == 2){
			echo '
			<form method="GET" class="changeResponsible" action="" style="float: right;"><b>Фильтр </b>
				<select class="responsible" onChange="this.form.submit();" name="response">
					<option value="0" '; if ($get['response'] == NULL) echo 'selected="selected"'; echo '>-</option>
					<option value="1" '; if ($get['response'] == 1) echo 'selected="selected"'; echo '>Виталик</option>
					<option value="3" '; if ($get['response'] == 3) echo 'selected="selected"'; echo '>Дима</option>
					<option value="4" '; if ($get['response'] == 4) echo 'selected="selected"'; echo '>Максим</option>
					<option value="5" '; if ($get['response'] == 5) echo 'selected="selected"'; echo '>Тема</option>
					<option value="6" '; if ($get['response'] == 6) echo 'selected="selected"'; echo '>Саша</option>
					<option value="99" '; if ($get['response'] == 99) echo 'selected="selected"'; echo '>Не закреплен</option>
				</select>

				<select class="responsible" onChange="this.form.submit();" name="status">
					<option value="99" '; if ($get['status'] == 99) echo 'selected="selected"'; echo '>-</option>
					<option value="0" '; if ($get['status'] == 0) echo 'selected="selected"'; echo '>не рассмотрено</option>
					<option value="1" '; if ($get['status'] == 1) echo 'selected="selected"'; echo '>отложено до лучших времен</option>
					<option value="2" '; if ($get['status'] == 2) echo 'selected="selected"'; echo '>в процессе</option>
					<option value="3" '; if ($get['status'] == 3) echo 'selected="selected"'; echo '>исправлено</option>
					<option value="4" '; if ($get['status'] == 4) echo 'selected="selected"'; echo '>мы не считаем это багом</option>
					<option value="5" '; if ($get['status'] == 5) echo 'selected="selected"'; echo '>удален</option>
				</select>
			</form><br/><br/>';
		}

	}

	/**
	 * отображение сообщений
	 */
	public static function displayListOfMessages($arrMessages){
		$size = sizeof($arrMessages);
		echo '
		<div class="blueTitle"><div><div><div><div>
			<!--<h1 class="blockName">Присланые сообщения</h1>-->
		</div></div></div></div></div>';
		echo '
		<table id="gotFeedbackTable">
			<tr>
				<th>ID</th>
				<th>Текст сообщения</th>
				<th>Пользователь</th>
				<th>Дата</th>
				<th>Статус</th>
			<tr>';
		foreach ($arrMessages as $message){
			echo '
			<tr>
				<td class="id">' . $message['ID_feed_back'] . '</td>
				<td>' .$message['text'] . '</td>
				<td class="user"><a href="' . W_ABSPATH . 'user/' . $message['login'] . '">' . $message['login'] . '</a></td>
				<td class="creation">' . Service_Date::getCaseDateForUser($message['creation']) . '</td>
				<td class="status">';
				switch ($message['status']){
					case 1: 
						echo '<a id="status' . $message['ID_feed_back'] . '" href="javascript:feedBackChangeMessageStatus(' . $message['ID_feed_back'] . ', 0)" class="none complete" title="поменять статус">обработан ' . str_replace(' ', '&nbsp;', User_User::getUserNameById($message['responsible'])) . '<a>';
						break;
					default: 
						echo '<a id="status' . $message['ID_feed_back'] . '" href="javascript:feedBackChangeMessageStatus(' . $message['ID_feed_back'] . ', 1)" class="none" title="поменять статус">не обработан<a>';
				}
			echo '
				</td>
			<tr>';
		}
		echo '
		</table>';
	}

	public static function showOneBug($arrBug){
  	$objSession = User_Session::instance();
  	View_TreeStructure::viewBreadcrumbs(array(0=>array('url'=>W_ABSPATH . 'bugs','name'=>'Баги'),
  																						1=>array('name'=>'Баг')));
  	echo '
						<div class="item">
							<div class="top_info_text">
								<ul class="rating">


									<li class="coments">
										<a href="#comments">' . $arrBug['comment_amount'] . '</a>
									</li>
								</ul>
								<div class="right_ifno_text">
									<ul class="info_coments">
										<li class="date">' . Service_Date::getCaseDateForUser($arrBug['creation']) . '</li>
										<li class="user"><a href="' . W_ABSPATH . 'user/' .  $arrBug['login'] . '">' . $arrBug['login'] . '</a></li>';
  									if ($arrBug['url'])
											echo '<li class="">Баг найден на <a href="' . W_ABSPATH . $arrBug['url'] . '">' . $arrBug['url'] . '</a></li>';
										echo '
									</ul>
								</div>
							</div>';

						echo '
					 </div>';
		  echo '<div class="text">
		  	<div class="text wysiwyg-content">' . $arrBug['text'] . '</div>
		  </div>';
	}
}
?>